package com.ff.neuropp.util;

import com.ff.neuropp.domain.CourseCategory;
import org.springframework.data.domain.Page;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResultTool<T> {

    public static Integer SuccessCode = 10000;
    public static Integer ErrorCode_1 = 10001;
    public static Integer ErrorCode_2 = 10002;



    public static Map<String, Object> genFailResult(Integer code,String message) {
        Map<String, Object> result = new HashMap<>();
        result.put("code",code);
        result.put("message",message);
        return result;
    }

    public static Map<String, Object> genSuccessResult(String message) {
        Map<String, Object> result = new HashMap<>();
        result.put("code",10000);
        result.put("message",message);
        return result;
    }
    public static Map<String, Object> genSuccessResult4Page(String message, Page list) {
        Map<String, Object> result4Page = new HashMap<>();
        result4Page.put("total",list.getTotalPages());
        result4Page.put("pageNo",list.getNumber()+1);
        result4Page.put("list",list.getContent());
        Map<String, Object> result = new HashMap<>();
        result.put("code",10000);
        result.put("message",message);
        result.put("data",result4Page);
        return result;
    }
    public static Map<String, Object> genSuccessResult(String message,Object data) {
//        System.out.println(data.getClass());
        Map<String, Object> result = new HashMap<>();
        result.put("code",10000);
        result.put("message",message);
        result.put("data",data);
        return result;
    }

    public static Map<String, Object> genSuccessResult(Object data) {
        Map<String, Object> result = new HashMap<>();
        result.put("code",10000);
        result.put("message","success");
        result.put("data",data);
        return result;
    }
}


